package org.lanqiao.webfm.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javacommon.base.BaseEntity;
import javacommon.util.DateConvertUtils;

/**
 * @author zhengwei
 * @version 1.0
 * @since 1.0
 */

public class RightsUser extends BaseEntity implements java.io.Serializable {
	private static final long serialVersionUID = 5454155825314635342L;

	// alias
	public static final String TABLE_ALIAS = "系统用户";
	public static final String ALIAS_ID = "标识";
	public static final String ALIAS_USERNAME = "用户名";
	public static final String ALIAS_PASSWORD = "密码";
	public static final String ALIAS_NAME = "真实姓名";
	public static final String ALIAS_STATUS = "状态";
	public static final String ALIAS_PHONENUMBER = "电话号码";
	public static final String ALIAS_ROLE_ID = "角色";
	public static final String ALIAS_ICON = "头像";

	//date formats
	public static final String FORMAT_BIRTHDAY = DATE_FORMAT;
	// columns START
	/**
	 * id db_column: ID
	 */

	private int id;
	
	/**
	 * username db_column: USERNAME
	 */
	private java.lang.String username;
	/**
	 * password db_column: PASSWORD
	 */
	private java.lang.String password;
	/**
	 * name db_column: NAME
	 */
	private java.lang.String name;
	/**
	 * 状态,1启用，2在线，3离线，9注销 db_column: STATUS
	 */
	private Integer status;
	/**
	 * phonenumber db_column: PHONENUMBER
	 */
	private java.lang.String phonenumber;
	/**
	 * roleId db_column: ROLE_ID
	 */

	private int roleId;

	private String icon="";
	/**生日**/
	private java.util.Date birthday;
	private java.util.Date birthdayBegin;
	private java.util.Date birthdayEnd;
	// columns END

	public RightsUser() {
	}

	public RightsUser(int id) {
		this.id = id;
	}
	public void setId(int value) {
		this.id = value;
	}

	public int getId() {
		return this.id;
	}

	public java.lang.String getUsername() {
		return this.username;
	}

	public void setUsername(java.lang.String value) {
		this.username = value;
	}

	public java.lang.String getPassword() {
		return this.password;
	}

	public void setPassword(java.lang.String value) {
		this.password = value;
	}

	public java.lang.String getName() {
		return this.name;
	}

	public void setName(java.lang.String value) {
		this.name = value;
	}

	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer value) {
		this.status = value;
	}

	public java.lang.String getPhonenumber() {
		return this.phonenumber;
	}

	public void setPhonenumber(java.lang.String value) {
		this.phonenumber = value;
	}

	public int getRoleId() {
		return this.roleId;
	}

	public void setRoleId(int value) {
		this.roleId = value;
	}

	//-----------关联的对象--------------
	private RightsRole rightsRole=new RightsRole();
	
	public RightsRole getRightsRole() {
		return rightsRole;
	}

	public void setRightsRole(RightsRole rightsRole) {
		this.rightsRole = rightsRole;
	}

	public List<String> getIconsList() {
		try {
            return Arrays.asList(icon.split(","));
        } catch (Exception e) {
            return null;
        }
	}
	public void addIcon(String icon) {
		if (icon.length()==0) {
			icon+=icon;
		}else {
			icon+=","+icon;
		}
	}

	public String getIcon() {
		/*StringBuilder sb = new StringBuilder();
		for (Iterator<String> iterator = iconsList.iterator(); iterator.hasNext();) {
			String icon = iterator.next();
			sb.append(icon);
			if (iterator.hasNext()) {
				sb.append(",");
			}
		}
		return sb.toString();*/
		return icon;
	}
	public void setIcon(String icons) {
		this.icon = icons;
	
	}
	public String getBirthdayString() {
		return DateConvertUtils.format(getBirthday(), FORMAT_BIRTHDAY);
	}
	public void setBirthdayString(String value) {
		setBirthday(DateConvertUtils.parse(value, FORMAT_BIRTHDAY,java.util.Date.class));
	}
	public java.util.Date getBirthdayBegin() {
		return this.birthdayBegin;
	}
	
	public void setBirthdayBegin(java.util.Date value) {
		this.birthdayBegin = value;
	}	
	
	public java.util.Date getBirthdayEnd() {
		return this.birthdayEnd;
	}
	
	public void setBirthdayEnd(java.util.Date value) {
		this.birthdayEnd = value;
	}	
	public void setBirthday(java.util.Date value) {
		this.birthday = value;
	}
	/**生日**/
	public java.util.Date getBirthday() {
		return this.birthday;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("Username",getUsername())
			.append("Password",getPassword())
			.append("Name",getName())
			.append("Status",getStatus())
			.append("Phonenumber",getPhonenumber())
			.append("RoleId",getRoleId())
			.append("Icon",getIcon())
			.append("Birthday",getBirthday())
			.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RightsUser other = (RightsUser) obj;
		if (id != other.id)
			return false;
		return true;
	}
}
